﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using LinFu.IoC.Configuration;
using LinFu.IoC.Interfaces;

namespace CoreEx.Wcf.Server.Tests
{
    [Factory(typeof(Binding))]
    public class BindingFactory : IFactory<Binding>
    {
        public Binding CreateInstance(IFactoryRequest request)
        {

            NetTcpBinding netTcpBinding = new NetTcpBinding();
            return netTcpBinding;

            var customBinding = new CustomBinding();

            var encodingBindingElement = new BinaryMessageEncodingBindingElement();
            encodingBindingElement.ReaderQuotas.MaxArrayLength = int.MaxValue;
            encodingBindingElement.ReaderQuotas.MaxDepth = int.MaxValue;
            encodingBindingElement.ReaderQuotas.MaxStringContentLength = int.MaxValue;
            var httpTransportBindingElement = new HttpTransportBindingElement();
            httpTransportBindingElement.TransferMode = TransferMode.Streamed;
            httpTransportBindingElement.MaxReceivedMessageSize = int.MaxValue;
            customBinding.Elements.Add(encodingBindingElement);
            customBinding.Elements.Add(httpTransportBindingElement);
            customBinding.SendTimeout = new TimeSpan(0, 10, 0);
            customBinding.ReceiveTimeout = new TimeSpan(0, 10, 0);
            return customBinding;
        }
    }
}
